#define _CRT_SECURE_NO_WARNINGS 1
int MIN = -1024 * 1024 * 1024 * 2;
int MAX = 1024 * 1024 * 1024 * 2 - 1;
class Solution {
public:
    int myAtoi(string str) {
        //str.reserse();
        string str2 = "";
        // int f=1;
        int i = 0;
        while (str[i] == ' ') {
            i++;
        }
        int f = 1;
        if (str[i] == '-' || str[i] == '+') {
            if (str[i] == '-')f = -1;
            i++;
        }

        long long num = 0;
        for (; i < str.size(); i++) {
            if (!(str[i] >= '0' && str[i] <= '9'))break;
            num = (long long)num * 10 + (str[i] - '0');
            //cout<<num<<" ";
            if (f == 1 && num > MAX) {
                num = MAX;
                break;
            }
            if (f == -1 && -num < MIN) {
                num = MIN;
                num = num * -1;
                break;
            }
        }

        // return num;
    }
};